/**
 * outsider.com.cn Inc.
 * Copyright (c) 2011-2022 All Rights Reserved.
 */
package com.yuanmeng.common.core.enums;

import com.yuanmeng.common.core.exception.ServiceException;
import lombok.Getter;

/**
 * @author outsider
 * @version Id: StatusEnum.java, v 0.1 2022/6/1 17:16 outsider Exp $$
 */
@Getter
public enum OrderTypeEnum {
    GENERAL("MP", "0", "商城普通订单"),

    SPIKE("MM", "1", "商城秒杀"),

    GROUP("MT", "2", "商城团购"),

    POINT("MJ", "3", "积分商品订单"),

    HOLIDAY("MH", "4", "节日活动订单");

    private String code;

    private String value;

    private String message;

    OrderTypeEnum(String code, String value, String message) {
        this.code = code;
        this.value = value;
        this.message = message;
    }

    public static String getEnumByCode(String value) {
        for(OrderTypeEnum ENUM : OrderTypeEnum.values()) {
            if(ENUM.value.equals(value)) {
                return ENUM.getCode();
            }
        }
        return "";
    }

    /**
     * 枚举值校验
     * @param orderType
     */
    public static void validateOrderTypeEnum(String orderType) {
        int num = 0;
        for(OrderTypeEnum ENUM : OrderTypeEnum.values()) {
            if(ENUM.value.equals(orderType)) {
                num++;
            }
        }
        if(num == 0) {
            throw new ServiceException("请求参数非法：orderType");
        }
    }

    public static String codeQueryValue(String orderType) {
        for(OrderTypeEnum ENUM : OrderTypeEnum.values()) {
            if(ENUM.code.equals(orderType)) {
                return ENUM.getMessage();
            }
        }
        return "";
    }

    public static String valueQueryCode(String orderTypeValue) {
        for(OrderTypeEnum ENUM : OrderTypeEnum.values()) {
            if(ENUM.message.equals(orderTypeValue)) {
                return ENUM.getCode();
            }
        }
        return "";
    }
}